<template>
    <div>
        <Modal v-model="loginmodal"
               title="登录"
               @on-ok="loginok"
               @on-cancel="logincancel">
            <Form :label-width="60">
                <FormItem label="用户名">
                    <Input v-model="user.username">
                        <Icon type="ios-contact" slot="prefix" />
                    </Input>
                </FormItem>
                <FormItem  label="密码">
                    <Input type="password" password v-model="user.password">
                    </Input>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
    export default {
        name: "login",
        props:{
            loginmodal:false,
        },
        data(){
            return{
                user: {
                    username: null,
                    password: null,
                    compellation:null
                },
            }
        },
        methods:{
            loginok(){
                this.axios.post("/lgoin",this.qs.stringify(this.user)).then((res)=>{
                    if (res.data){
                        this.$parent.loginstatus = true //改变父组件的变量
                        this.$message.success('登录成功')
                        this.$parent.loginmodal = false
                        this.user.compellation  = res.data.compellation
                        sessionStorage.setItem("username",res.data.username)
                        this.$emit("passByValue",res.data)

                    }else{
                        this.$Message.error('账号或密码有误！！！')
                    }
                })
            },
            logincancel(){
                this.$parent.loginmodal = false
            }
        }
    }
</script>

<style scoped>

</style>